<!DOCTYPE html>
<html lang="zh-CN">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  
  <title itemprop="name">浙大Python基础课笔记 | lichen</title>
  
    <link rel="shortcut icon" href="/images/favicon.ico">
  
  <meta http-equiv="x-dns-prefetch-control" content="on">
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Noto+SerifMerriweather|Merriweather+Sans|Source+Code+Pro|Ubuntu:400,700|Noto+Serif+SC" media="all">
  <link rel="dns-prefetch" href="//cdn.jsdelivr.net">
  <link rel="stylesheet" id="saukra_css-css" href="/css/style.css" type="text/css" media="all">
  <link rel="stylesheet" href="/css/lib.min.css" media="all">
  <link rel="stylesheet" href="/css/font.css" media="all">
  <link rel="stylesheet" href="/css/insight.css" media="all">
  <link rel="stylesheet" href="/css/jquery.fancybox.min.css" media="all">
  <link rel="stylesheet" href="/css/zoom.css" media="all">
  <link rel="stylesheet" type="text/css" href="/css/sharejs.css">
<!--   <link rel="stylesheet" id="saukra_css-css" href="https://2heng.xin/wp-content/cache/autoptimize/css/autoptimize_ad42a61f4c7d4bdd9f91afcff6b5dda5.css
" type="text/css" media="all"> -->
  <script>
  /*Initial Variables*/
  var mashiro_option = new Object();
  var mashiro_global = new Object();
  mashiro_option.NProgressON = true;
  /* 
   * 邮箱信息之类的东西可以填在这里，这些js变量基本都作用于sakura-app.js
   * 这样的设置仅是为了方便在基于PHP开发的主题中设置js变量，既然移植到了Node上，我想或许可以精简这一逻辑吧
   */
  mashiro_option.email_domain = "";
  mashiro_option.email_name = "";
  mashiro_option.cookie_version_control = "";
  mashiro_option.qzone_autocomplete = false;
  mashiro_option.site_name = "LCsite";
  mashiro_option.author_name = "site";
  mashiro_option.site_url = "https://lichen312.gitee.io/blog/";
  mashiro_option.v_appId = "GyC3NzMvd0hT9Yyd2hYIC0MN-gzGzoHsz";
  mashiro_option.v_appKey = "mgOpfzbkHYqU92CV4IDlAUHQ";
  mashiro_option.mathjax = "0";
  mashiro_option.qq_api_url = "https://api.mashiro.top/qqinfo/"; 
  mashiro_option.qq_avatar_api_url = "https://api.mashiro.top/qqinfo/";

  // mashiro_option.jsdelivr_css_src = "https://cdn.jsdelivr.net/gh/moezx/cdn@3.4.5/css/lib.min.css";
  // mashiro_option.float_player_on = true;

  /*End of Initial Variables*/
  </script>
  <script type="text/javascript">
  var bg = "https://gitee.com/lichen312/picbed/raw/master/image/flower.jpg,https://gitee.com/lichen312/picbed/raw/master/image/sakura.png".split(",");
  var bgindex = Math.floor(Math.random()*bg.length);
  if (!!window.ActiveXObject || "ActiveXObject" in window) { //is IE?
    alert('朋友，IE浏览器未适配哦~');
  }
  </script>
  <style type="text/css">
  .hljs-ln{border-collapse:collapse}.hljs-ln td{padding:0}.hljs-ln-n:before{content:attr(data-line-number)}
  </style>
  <style type="text/css">.site-top .lower nav{display:block !important;}.author-profile i,.post-like a,.post-share .show-share,.sub-text,.we-info a,span.sitename,.post-more i:hover,#pagination a:hover,.post-content a:hover,.float-content i:hover{color:#FE9600}.feature i,.download,.navigator i:hover,.links ul li:before,.ar-time i,span.ar-circle,.object,.comment .comment-reply-link,.siren-checkbox-radio:checked + .siren-checkbox-radioInput:after{background:#FE9600}::-webkit-scrollbar-thumb{background:#FE9600}.download,.navigator i:hover,.link-title,.links ul li:hover,#pagination a:hover,.comment-respond input[type='submit']:hover{border-color:#FE9600}.entry-content a:hover,.site-info a:hover,.comment h4 a,#comments-navi a.prev,#comments-navi a.next,.comment h4 a:hover,.site-top ul li a:hover,.entry-title a:hover,#archives-temp h3,span.page-numbers.current,.sorry li a:hover,.site-title a:hover,i.iconfont.js-toggle-search.iconsearch:hover,.comment-respond input[type='submit']:hover{color:#FE9600}.comments .comments-main{display:block !important;}.comments .comments-hidden{display:none !important;}background-position:center center;background-attachment:inherit;}
  </style>
</head>
</html>
<body class="page-template page-template-user page-template-page-analytics page-template-userpage-analytics-php page page-id-1297 chinese-font serif isWebKit">
  <div class="scrollbar" id="bar">
  </div>
  <a href="#" class="cd-top faa-float animated"></a>
  <section id="main-container">
    <div class="headertop filter-dot">
  <div id="banner_wave_1"></div>
  <div id="banner_wave_2"></div>
  <figure id="centerbg" class="centerbg">
    <div class="focusinfo no-select">
      <div class="header-tou">
        <a href="https://lichen312.gitee.io/blog/">
          <img src="https://gitee.com/lichen312/picbed/raw/master/image/20210124214938.png">
        </a>
      </div>
      <div class="header-info">
        <p>莫要三天打鱼,两天晒网!</p>
        <div class="top-social_v2">
          <li id="bg-pre">
            <img class="flipx" src="https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/other/next-b.svg">
          </li>
          
          <li id="bg-next">
            <img src="https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/other/next-b.svg">
          </li>
        </div>
      </div>
    </div>
  </figure>
  <div id="video-container" style="">
    <video style="object-fit: fill" id="bgvideo" class="video" video-name="" src="" width="auto" preload="auto">
    </video>
    <div id="video-btn" class="loadvideo videolive">
    </div>
    <div id="video-add">
    </div>
    <div class="video-stu">
    </div>
  </div>
  <div class="headertop-down faa-float animated" onclick="headertop_down()">
    <span>
      <i class="fa fa-chevron-down" aria-hidden="true">
      </i>
    </span>
  </div>
</div>
    <div id="page" class="site wrapper">
      <header class="site-header no-select gizle sabit" role="banner">
  <div class="site-top">
    <div class="site-branding">
      <span class="site-title">
        <span class="logolink moe-mashiro">
          <a href="/">
            <span class="sakurasono">LC</span>
            <span class="shironeko">site</span>
          </a>
        </span>
      </span>
    </div>
    <div class="searchbox search-form-submit">
      <i class="iconfont js-toggle-search iconsearch icon-search">
      </i>
    </div>
    <div id="show-nav" class="showNav mobile-fit">
      <div class="line line1">
      </div>
      <div class="line line2">
      </div>
      <div class="line line3">
      </div>
    </div>
    <div class="lower-cantiner">
      <div class="lower">
        <nav class="mobile-fit-control hide">
          <ul id="menu-new" class="menu">
            
              <li>
                <a href="/">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-fort-awesome faa-shake" aria-hidden="true"></i>
                    首页
                  </span>
                </a>
                
              </li>
            
              <li>
                <a href="/archives">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-archive faa-shake" aria-hidden="true"></i>
                    归档
                  </span>
                </a>
                
              </li>
            
              <li>
                <a href="javascript:;">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-list-ul faa-vertical" aria-hidden="true"></i>
                    (๑•̀ㅂ•́)و✧
                  </span>
                </a>
                
              </li>
            
              <li>
                <a href="/comment/">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-pencil-square-o faa-tada" aria-hidden="true"></i>
                    留言板
                  </span>
                </a>
                
              </li>
            
              <li>
                <a href="/donate/">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-heart faa-pulse" aria-hidden="true"></i>
                    赞赏
                  </span>
                </a>
                
              </li>
            
              <li>
                <a href="javascript:;">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-link faa-shake" aria-hidden="true"></i>
                    (ノへ￣、)
                  </span>
                </a>
                
              </li>
            
              <li>
                <a href="/">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-leaf faa-wrench" aria-hidden="true"></i>
                    关于
                  </span>
                </a>
                
                  <ul class="sub-menu">
                    
                      <li>
                        <a href="/about/">
                          <i class="fa fa-meetup" aria-hidden="true"></i>
                          我？
                        </a>
                      </li>
                    
                      <li>
                        <a href="/theme-sakura/">
                          <i class="fa iconfont icon-sakura" aria-hidden="true"></i>
                          主题
                        </a>
                      </li>
                    
                  </ul>
                
              </li>
            
              <li>
                <a href="/atom.xml">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-rss faa-pulse" aria-hidden="true"></i>
                    RSS
                  </span>
                </a>
                
              </li>
            
          </ul>
        </nav>
      </div>
    </div>
  </div>
</header>

      <link rel="stylesheet" type="text/css" href="/css/sharejs.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.4.2/tocbot.css">
<div class="pattern-center-blank"></div>

  <div class="pattern-center single-center">
    <!-- 有配图默认渲染第一张 -->
    <div class="pattern-attachment-img lazyload" style="background-image: url(https://gitee.com/lichen312/picbed/raw/master/image/python.png);" src="https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/loader/orange.progress-bar-stripe-loader.svg" data-src="https://gitee.com/lichen312/picbed/raw/master/image/python.png">
    </div>
    <header class="pattern-header single-header">
      <h1 class="entry-title">
      浙大Python基础课笔记</h1>
      <p class="entry-census">
        <span>
          <a href="https://http://lichen312.gitee.io/">
            <img src="https://gitee.com/lichen312/picbed/raw/master/image/20210124214938.png">
          </a>
        </span>
        <span>
          <a href="https://http://lichen312.gitee.io/">LC</a>
        </span>
        <span class="bull">
        ·</span>
        2021-11-11<span class="bull">
        ·</span>
      <span id="busuanzi_value_page_pv"></span>次阅读</p>
      <!-- 开始添加字数统计-->
      
        
<div style="margin-top:10px;">
    <span class="post-time">
      <span class="post-meta-item-icon">
        <i class="fa fa-keyboard-o"></i>
        <span class="post-meta-item-text">  字数统计: </span>
        <!-- 安装插件npm install hexo-wordcount --save -->
        <span class="post-count">2.4k字</span>
      </span>
    </span>

    <span class="post-time">
      &nbsp; | &nbsp;
      <span class="post-meta-item-icon">
        <i class="fa fa-hourglass-half"></i>
        <span class="post-meta-item-text">  阅读时长: </span>
        <span class="post-count">10分</span>
      </span>
    </span>
</div>

      
      <!-- 添加完成 -->
      
    </header>
  </div>

<div id="content" class="site-content">
  <div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">
      <article id="post-1" class="post-1 post type-post status-publish format-standard has-post-thumbnail hentry category-uncategorized">
        <div class="toc"></div>
        <!--<div class="toc-entry-content"><!-- 套嵌目录使用（主要为了支援评论）-->
        
        <div class="entry-content">
          <p>​    浙江大学Python基础课的笔记。</p>
<hr>
<h1 id="浙大python基础学习"><a href="#浙大python基础学习" class="headerlink" title="浙大python基础学习"></a>浙大python基础学习</h1><h2 id="第一章-python概述"><a href="#第一章-python概述" class="headerlink" title="第一章.python概述"></a>第一章.python概述</h2><ul>
<li>变量对比c/c艹有哪些不同？  <ol>
<li>python的变量不需要定义，类型可以自动转换</li>
<li>int类型的变量没有范围</li>
<li>浮点型一样有精度限制</li>
</ol>
</li>
<li>输入输出？  <ol>
<li>input()函数用来输入，读取到的是字符串，要读取别的类型使用类型转换即可</li>
<li>print()函数用来输出，默认输出换行，结尾符号可以用end参数改变，例如：print(a,end = ‘-‘)<pre><code class="python">print(&quot;hellow&quot;,end = &#39;-&#39;);
&gt;&gt;&gt; hellow-
</code></pre>
</li>
</ol>
</li>
</ul>
<h2 id="第二章-用python编写程序"><a href="#第二章-用python编写程序" class="headerlink" title="第二章.用python编写程序"></a>第二章.用python编写程序</h2><ul>
<li>运算符和c/c++有什么不同？  <ol>
<li>/是浮点除法，3/5 = 0.6</li>
<li>//整数除法，5//2 = 2； -5//2 = -3 (向下取整)</li>
<li>**次方，2**3 = 8</li>
<li>%可以求浮点余数，但是有误差</li>
</ol>
</li>
<li><p>字符串  </p>
<ol>
<li>字符串可以用’,”,’’’,来表示，后面的表示可以覆盖前面的引号不用转义，并且’’’可以表示多行文本</li>
<li>字符串索引可以是﹣的，也就是s[-1]表示倒数第一个字符</li>
<li>切片<pre><code class="python">s = &#39;hellow&#39;
s[1:3]
&gt;&gt;&gt; &#39;el&#39;
</code></pre>
</li>
</ol>
</li>
<li><p>关系运算  </p>
<ol>
<li>可以多个结合<pre><code class="python">1 &lt; 3 &lt; 6
&gt;&gt;&gt; True
</code></pre>
</li>
</ol>
</li>
</ul>
<h2 id="第三章-使用字符串，列表，元组"><a href="#第三章-使用字符串，列表，元组" class="headerlink" title="第三章.使用字符串，列表，元组"></a>第三章.使用字符串，列表，元组</h2><ul>
<li>序列访问和运算符  <ol>
<li>字符串就是列表</li>
<li>可以相加，*表示复制多份，[1,2,3]*2 = [1,2,3,1,2,3,]</li>
<li>有方便的判断元素存在的方法<pre><code class="python">2 in [1,2]
&gt;&gt;&gt; True
[1,2] in [1,2,3]
&gt;&gt;&gt; False
[1,2] in [[1,2],3]
&gt;&gt;&gt; True
</code></pre>
</li>
</ol>
</li>
<li>列表  <ol>
<li>列表中的元素可以是不同的类型</li>
<li>list函数将别的类型转换成列表<pre><code class="python">l = list(&quot;list&quot;)
l
&gt;&gt;&gt; [&#39;l&#39;,&#39;i&#39;,&#39;s&#39;,&#39;t&#39;]
</code></pre>
</li>
<li>列表变量是管理者，同java，管理同一个列表时改变会互相影响<pre><code class="python">l1 = [1,2,3]
l2 = l1
l2[0] = 0
l1
&gt;&gt;&gt; [0,2,3]
#正确用法，使用切片
l2 = l1[:]
</code></pre>
</li>
<li>删除列表元素，使用del函数</li>
</ol>
</li>
</ul>
<p>+元组<br>   和列表一样，但是用()表示，并且里面的元素不可更改(也包括不可以增加和删除元素)  </p>
<h2 id="第四章-条件，循环和其他语句"><a href="#第四章-条件，循环和其他语句" class="headerlink" title="第四章.条件，循环和其他语句"></a>第四章.条件，循环和其他语句</h2><ul>
<li>条件语句<ol>
<li>条件语句用缩进表示if和else的关系<pre><code class="python">if 1 &gt; 2:
  print(&quot;1&gt;2&quot;)
else:
  print(&quot;1&lt;2&quot;)
&gt;&gt;&gt; 1&gt;2
</code></pre>
</li>
</ol>
</li>
<li>循环<ol>
<li>for-else   <pre><code class="python">for i in range(0,3)
#等价于C++中
for(int i = 0; i &lt; 3; i++)
#----------------------------
#带else的情况下，不是break跳出的时候回执行else后面的代码
for i in range(0,3)
 print(i,end = &#39; &#39;)
else:
 print(&quot;end&quot;)
&gt;&gt;&gt; 0 1 2 end
</code></pre>
</li>
<li>range函数，第一个参数开始，到第二个参数结束，开始默认为0,第三个参数可以设置间隔<pre><code class="python">range(0,4) --&gt; [0,1,2,3]
range(1,3) --&gt; [1,2]
range(3)   --&gt; [0,1,2]
range(2,20,3) --&gt; [2,5,8,11,14,17]
range(3,0,-1) --&gt; [3,2,1]
</code></pre>
</li>
</ol>
</li>
<li><p>异常<br>  使用try和except来处理异常，和java类似</p>
<pre><code class="python">  try:
      do something
  except 异常类型:
      处理异常
  else:
      没有异常发生执行的语句
  finally:
      无论有没有异常都执行的语句

</code></pre>
<h2 id="第五章-集合与字典"><a href="#第五章-集合与字典" class="headerlink" title="第五章.集合与字典"></a>第五章.集合与字典</h2></li>
<li>集合  <ol>
<li>用add(),remove()添加或者删除元素</li>
<li>集合元素不能重复，集合无序，所以不能用下标索引</li>
<li>集合字典公用{}，{}有数据的时候表示集合，没数据的时候表示空字典，空集合用set()得到</li>
</ol>
</li>
<li>字典  <ol>
<li>字典和hashmap类似，是key和value的对应关系 <pre><code class="python">map = {&#39;one&#39;:1,&#39;two&#39;:2}
map[&#39;one&#39;]
&gt;&gt;&gt; 1
map[&#39;three&#39;] = 3
map[&#39;three&#39;]
&gt;&gt;&gt; 3
</code></pre>
</li>
<li>for循环拿到的是key<pre><code class="python">for key in map:
#key依次等于字典中的每个key
</code></pre>
</li>
<li>最好用方法访问，这样不会出异常<pre><code class="python">#当1不存在时
map[1] --&gt; 出现异常
map.get(1) --&gt; 什么都不返回
map.get(1,0) --&gt; 返回一个0
</code></pre>
</li>
</ol>
</li>
</ul>
<h2 id="第六章-函数"><a href="#第六章-函数" class="headerlink" title="第六章.函数"></a>第六章.函数</h2><ul>
<li>函数定义<pre><code class="python">  def 函数名(参数表):
      函数体
  #lambda简单定义
  s = lambda x:-x
  s(1)
  &gt;&gt;&gt; -1
</code></pre>
</li>
<li>函数参数  <ol>
<li>默认值参数只初始化一次<pre><code class="python">def add_value(n,result = []):
 result.append(n)
 print(result)
add_value(1)
add_value(2)
add_value(3,[1])
&gt;&gt;&gt; [1]
&gt;&gt;&gt; [1,2]
&gt;&gt;&gt; [1,3]
</code></pre>
</li>
<li>可变参数个数<pre><code class="python">def test(a,*b):
 print(a)
 print(b)
#得到参数a,a之后的参数放到b中组成一个元组
test(1,2,3)
&gt;&gt;&gt; 1
&gt;&gt;&gt; (2,3)
</code></pre>
</li>
<li>可变参数放在字典里<pre><code class="python">def test(a,**b):
 print(b)
test(1,x1 = 9,x2 = 3)
&gt;&gt;&gt; {&#39;x1&#39;:9,&#39;x2&#39;:3}
</code></pre>
</li>
<li>实参拆包<pre><code class="python">l = [1,2,3]
print(l)
&gt;&gt;&gt; [1,2,3]
print(*l)
&gt;&gt;&gt; 1 2 3
</code></pre>
5.列表和c++一样会影响外面<pre><code class="python">def test(l):
 l[1] = 0
l = [1,2,3]
test(l)
print(l)
&gt;&gt;&gt; [1,0,3]
</code></pre>
</li>
</ol>
</li>
<li>返回值  <ol>
<li>返回值可以是函数</li>
<li>没有返回值的时候返回一个特殊的None</li>
</ol>
</li>
<li>命名空间和作用域<br>  Python解释器启动时建立一个全局命名空间，全局变量就<br>  放在这个空间，还建立内置命名空间(built-in namespace),<br>  记录所有标准常量名、标准函数名等。在全局命名空间<br>  中定义的变量是全局变量。<br>  全局变量使用的时候用global申明<br>  使用dir()可以查看空间中的名字<pre><code class="python">  def test():
      global v1
      v1 = 3
      print(v1,v2)
  v1 = 1
  v2 = 2
  test()
  print(v1)
  &gt;&gt;&gt; 3 2
  &gt;&gt;&gt; 3
</code></pre>
</li>
<li>内置函数<ol>
<li>sort和sorted,sort把列表排序而sorted排序生成新列表，原来的列表不变<br>sorted可以对除了list以外的对象排序<pre><code class="python">student = [[&#39;张三&#39;,11],[&#39;李四&#39;,9]]
sorted(student,key = lambda s:s[1])
&gt;&gt;&gt; [[&#39;李四&#39;,9],[&#39;张三&#39;,11]]
</code></pre>
</li>
<li>map()对函数和参数进行匹配<pre><code class="python">def square(x) :         # 计算平方数
 return x ** 2
map(square, [1,2,3,4,5])    # 计算列表各个元素的平方
&gt;&gt;&gt; &lt;map object at 0x100d3d550&gt;     # 返回迭代器
list(map(square, [1,2,3,4,5]))   # 使用 list()转换为列表
&gt;&gt;&gt; [1, 4, 9, 16, 25]
</code></pre>
</li>
<li>zip()打包列表<pre><code class="python">a = [1,2,3]
b = [4,5,6]
zip(a,b)
&gt;&gt;&gt; [(1,4),(2,5),(3,6)]
#使用zip实现字典key和value互换
d = {&#39;one&#39;:1,&#39;two&#39;:2}
d1 = dict(zip(d,value(),d.(key)))
print(d1)
&gt;&gt;&gt; {1:&#39;one&#39;,2:&#39;two&#39;}
</code></pre>
</li>
<li>eval和exec<br>目前不知道有什么应用，暂且放着，用到的时候再仔细看看</li>
<li>all和any<br>all():全是True的时候返回True<br>any():只要有一个True就返回True</li>
</ol>
</li>
<li>程序结构  <ol>
<li>import<pre><code class="python">#引入文件
import test.py
#引入模块(模块名和文件名一样)
import test
#引入模块的函数/变量/类
from test import fuc
</code></pre>
</li>
<li>以主程序方式运行<pre><code class="python">if __name__ = &#39;__main__&#39;:
 do something
#只有再运行该文件的时候才运行语句，不然忽略。没有这句的话就会导致别的文件import的时候会运行该模块的语句
</code></pre>
</li>
<li>包<br>模块可以放在一个文件夹里面组成一个包，文件夹含有<strong>init</strong>.py文件，目的是为了简化impor，具体可以查看：<br><a href="https://www.jianshu.com/p/73f7fbf75183" target="_blank" rel="noopener"><strong>init</strong>的用法</a></li>
</ol>
</li>
</ul>
<h2 id="第七章-文件"><a href="#第七章-文件" class="headerlink" title="第七章.文件"></a>第七章.文件</h2><ul>
<li>文件读写<br>  和c++差不多，创建文件对象然后打开文件进行读写，关闭文件，需要用到的时候查相关的方法即可</li>
<li>Pandas模块<br>  一个可以方便处理数据的模块</li>
</ul>
<h2 id="第八章-类和对象"><a href="#第八章-类和对象" class="headerlink" title="第八章.类和对象"></a>第八章.类和对象</h2><ul>
<li><p>创建类，和c++差不多，语法不一样而已，不多做说明</p>
<pre><code class="python">  class student:
      def __init__(self,name,grad):  #构造函数
          self.name = name
          self.grad = grad
      def print(self):
          print(self.name,self.grad) #注意用属性的时候加self才行

  s = student(&#39;张三&#39;,3)
  s.print()
  &gt;&gt;&gt; 张三 3
  isinstance(s,student) #判断一个实例是不是某个对象的实例
  &gt;&gt;&gt; True
</code></pre>
</li>
<li><p>类变量和实例变量<br>  就是C++类里面的普通变量和static变量</p>
<pre><code class="python">  class student:
      school = &#39;FZU&#39;
      #类变量，可以用类名访问，所有实例共享(C++static变量)
      def __init__(self,name,grad):  #构造函数
          self.name = name #实例变量,实例占有
          self.grad = grad
</code></pre>
</li>
<li><p>实例方法，类方法，静态类方法</p>
<pre><code class="python">  class student:
      school = &#39;FZU&#39;
      def __init__(self,name,grad):
          self.name = name
          self.grad = grad
      @classmethod  #必须有，不然解释器解释为实例方法
      def fuc1(cls): #可以用类名调用，只能访问类变量
          print(&quot;类方法&quot;)
      @staticmethod #必须有，不然解释器解释为实例方法
      def fuc2()  #可以用类名调用，无法访问类变量和实例变量
          print(&quot;静态类方法&quot;)
</code></pre>
</li>
<li>私有和公有成员  <pre><code class="python">  #命名的时候前置下划线
  __xx__ --&gt; 系统定义的特殊成员，比如构造函数__init__
  _xx --&gt; 受保护的成员，只有类和子类能访问，不能import
  __xx --&gt; 私有成员，只有类能访问，子类不能
</code></pre>
</li>
<li><p>继承和多态<br>  和别的面对对象语言一样，只要举个实例记住语法即可</p>
<pre><code class="python">  class car:
  def __init__(self,name,color):
      self._name = name
      self._color = color
  def print(self):
      print(&quot;a&quot;,self._color,&quot;car named&quot;,self._name )

  class Ecar(car):    #继承语法
      def __init__(self,name,color):
          super().__init__(name,color)   #调用父类构造函数
      def print(self):    #重载父类方法，实现多态
          print(&quot;a&quot;,self._color,&quot;Ecar named&quot;,self._name )

  c = Ecar(&quot;jeep&quot;,&quot;white&quot;)
  c.print()
  &gt;&gt;&gt; a white Ecar named jeep
</code></pre>
</li>
<li>深拷贝和浅拷贝<br>  浅拷贝就是拷贝了地址，指向同一个实例，深拷贝使用copy的deepcopy方法，创建一个新的实例，然后复制另一个实例的值，是不同的实例。</li>
</ul>

        </div>
        <!-- .entry-content -->
        <div class="single-reward">
          <div class="reward-open">赏
            <div class="reward-main">
              <ul class="reward-row">
                <li class="alipay-code"><img src="https://gitee.com/lichen312/picbed/raw/master/image/aly_get.png"></li>
                <li class="wechat-code"><img src="https://gitee.com/lichen312/picbed/raw/master/image/wechat_get.png"></li>
              </ul>
            </div>
          </div>
        </div>
        <div style="text-align:center; width: 100%" class="social-share share-mobile" data-disabled="diandian, tencent"></div>
        <footer class="post-footer">
          <div class="post-lincenses"><a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" target="_blank" rel="nofollow"><i class="fa fa-creative-commons" aria-hidden="true"></i> 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议</a></div>
          <div class="post-tags">
          </div>
          <div class="post-share">
            <div class="social-share sharehidden share-component"></div>
            <i class="iconfont show-share icon-forward"></i>
          </div>
        </footer><!-- .entry-footer -->
      </article>
      <!-- #post-## -->
      <div class="toc" style="background: none;"></div>
      <section class="post-squares nextprev">
        
          
            <div class="post-nepre half previous">
          
            <a href="/2021/11/11/hexo采坑/" rel="prev">
              <div class="background">
                <img class="lazyload" src="https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/loader/orange.progress-bar-stripe-loader.svg" data-src="https://gitee.com/lichen312/picbed/raw/master/image/hexo.png" style="width: 100%; height: 100%; object-fit: cover; pointer-events: none;" onerror="imgError(this,3)" src="https://gitee.com/lichen312/picbed/raw/master/image/hexo.png">
              </div>
              <span class="label">
              Previous Post</span>
              <div class="info">
                <h3>
                HEXO的使用和遇到的一些坑</h3>
                <hr>
              </div>
            </a>
          </div>
        
        
          
            <div class="post-nepre half next">
          
            <a href="/2021/01/24/markdown基础语法/" rel="next">
              <div class="background">
                <img class="lazyload" src="https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/loader/orange.progress-bar-stripe-loader.svg" data-src="https://gitee.com/lichen312/picbed/raw/master/image/note-taking.png" style="width: 100%; height: 100%; object-fit: cover; pointer-events: none;" onerror="imgError(this,3)" src="https://gitee.com/lichen312/picbed/raw/master/image/note-taking.png">
              </div>
              <span class="label">
              Next Post</span>
              <div class="info">
                <h3>
                markdown基础语法</h3>
                <hr>
              </div>
            </a>
          </div>
        
      </section>
      
      <section class="author-profile">
        <div class="info" itemprop="author" itemscope="" itemtype="https://schema.org/Person">
          <a href="https://http://lichen312.gitee.io/" class="profile gravatar"><img src="https://gitee.com/lichen312/picbed/raw/master/image/20210124214938.png" itemprop="image" alt="LC" height="70" width="70"></a>
          <div class="meta">
            <span class="title">Author</span>
            <h3 itemprop="name">
            <a href="https://http://lichen312.gitee.io/" itemprop="url" rel="author">LC</a>
            </h3>
          </div>
        </div>
        <hr>
        <p><i class="iconfont icon-write"></i>菜鸡罢了</p>
      </section>
    </main><!-- #main -->
  </div><!-- #primary -->
</div>



    </div>    
    <div class="ins-search">
    <div class="ins-search-mask"></div>
    <div class="ins-search-container">
        <div class="ins-input-wrapper">
            <input type="text" class="ins-search-input" placeholder="请输入关键词..."/>
            <span class="ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            // PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
        },
        ROOT_URL: '/',
        CONTENT_URL: '/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
    <!-- <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2022 lichen<br>
      powered_by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer> -->
<footer id="colophon" class="site-footer" role="contentinfo">
  <div class="site-info">
    <div class="footertext">
      <div class="img-preload">
        <img src="https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/other/wordpress-rotating-ball-o.svg">
        <img src="https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/other/disqus-preloader.svg">
      </div>
      <p style="color: #666666;">&copy 2018</p>
    </div>
    <div class="footer-device">
    <p style="font-family: 'Ubuntu', sans-serif;">
        <span style="color: #b9b9b9;">Theme <a href="https://github.com/honjun/hexo-theme-sakura" target="_blank" style="color: #b9b9b9;;text-decoration: underline dotted rgba(0, 0, 0, .1);">Sakura</a> <i class="iconfont icon-sakura rotating" style="color: #ffc0cb;display:inline-block"></i> by <a href="https://2heng.xin/" target="_blank" style="color: #b9b9b9;;text-decoration: underline dotted rgba(0, 0, 0, .1);">Mashiro</a>&<a href="https://www.hojun.cn/" target="_blank" style="color: #b9b9b9;;text-decoration: underline dotted rgba(0, 0, 0, .1);">Hojun</a>, Powered by Hexo, Hosted by Coding Pages</a>
        </span>
      </p>
    </div>
  </div><!-- .site-info -->
</footer>



<!-- <script src="/js/tocbot.js"></script> -->
<script type="text/javascript" src="/js/lib.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script type="text/javascript" src="/js/InsightSearch.js"></script>
<script type="text/javascript" src="/js/jquery.fancybox.min.js"></script>
<script type="text/javascript" src="/js/zoom.min.js"></script>
<script type="text/javascript" src="/js/sakura-app.js"></script>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='//unpkg.com/valine@1.3.4/dist/Valine.min.js'></script>
<script src="/js/botui.js"></script>
<!-- 不蒜子 网页计数器 -->
<script src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.4.2/tocbot.min.js"></script> -->
<script type="text/javascript">
/* <![CDATA[ */
if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
  var Poi = {"pjax":"1","movies":{"url": "https://cdn.jsdelivr.net/gh/honjun/hojun@1.2","name":"Unbroken.mp4","live":"close"},"windowheight":"fixed","codelamp":"close","ajaxurl":"","order":"asc","formpostion":"bottom"};
} else {
  var Poi = {"pjax":"1","movies":{"url": "https://cdn.jsdelivr.net/gh/honjun/hojun@1.2","name":"Unbroken.mp4","live":"open"},"windowheight":"auto","codelamp":"close","ajaxurl":"","order":"asc","formpostion":"bottom"};
}
/* ]]> */

</script>
<script>
$(document).ready(function() {
  if ($(".toc").length > 0 && document.body.clientWidth > 1200) {
    if ($(".pattern-center").length > 0) { //有图的情况
      tocbot.init({
          // Where to render the table of contents.
          tocSelector: '.toc', // 放置目录的容器
          // Where to grab the headings to build the table of contents.
          contentSelector: '.entry-content', // 正文内容所在
          // Which headings to grab inside of the contentSelector element.
          scrollSmooth: true,
          headingSelector: 'h1, h2, h3, h4, h5', // 需要索引的标题级别
          headingsOffset: -400,
          scrollSmoothOffset: -85
      });
    } else {
      tocbot.init({
          // Where to render the table of contents.
          tocSelector: '.toc', // 放置目录的容器
          // Where to grab the headings to build the table of contents.
          contentSelector: '.entry-content', // 正文内容所在
          // Which headings to grab inside of the contentSelector element.
          scrollSmooth: true,
          headingSelector: 'h1, h2, h3, h4, h5', // 需要索引的标题级别
          headingsOffset: -85,
          scrollSmoothOffset: -85
      });
    }
    var offsetTop = $('.toc').offset().top - 95;
    window.onscroll = function() {
      var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
      if (scrollTop >= offsetTop) {
        $('.toc').addClass('toc-fixed');
      } else {
        $('.toc').removeClass('toc-fixed');
      }
    }
  }
});
</script>

    <div class="openNav no-select" style="height: 50px;">
      <div class="iconflat no-select" style="width: 50px; height: 50px;">
        <div class="icon"></div>
      </div>
      <div class="site-branding search-form-submit">
        <i class="iconfont js-toggle-search iconsearch icon-search"></i>
      </div>
    </div>
  </section>
  <div id="mo-nav" class="">
  <div class="m-avatar">
    <img src="https://gitee.com/lichen312/picbed/raw/master/image/20210124214938.png">
  </div>
  <p style="text-align: center; color: #333; font-weight: 900; font-family: 'Ubuntu', sans-serif; letter-spacing: 1.5px">LCsite</p>
  <p style="text-align: center; word-spacing: 20px;">
    
      
        <a href="http://github.com/honjun" class="fa fa-github" target="_blank" style="color: #333; margin-left:20px"></a>
      
        <a href="http://weibo.com/mashirozx?is_all=1" class="fa fa-weibo" target="_blank" style="color: #dd4b39; margin-left:20px"></a>
      
        <a href="https://wpa.qq.com/msgrd?v=3&uin=954655431&site=qq&menu=yes" class="fa fa-qq" target="_blank" style="color: #25c6fe; margin-left:20px"></a>
      
    
  </p>
  <ul id="menu-new-1" class="menu">
    
      <li>
        <a href="/">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-fort-awesome faa-shake" aria-hidden="true"></i>
            首页
          </span>
        </a>
        
      </li>
    
      <li>
        <a href="/archives">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-archive faa-shake" aria-hidden="true"></i>
            归档
          </span>
        </a>
        
      </li>
    
      <li>
        <a href="javascript:;">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-list-ul faa-vertical" aria-hidden="true"></i>
            (๑•̀ㅂ•́)و✧
          </span>
        </a>
        
      </li>
    
      <li>
        <a href="/comment/">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-pencil-square-o faa-tada" aria-hidden="true"></i>
            留言板
          </span>
        </a>
        
      </li>
    
      <li>
        <a href="/donate/">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-heart faa-pulse" aria-hidden="true"></i>
            赞赏
          </span>
        </a>
        
      </li>
    
      <li>
        <a href="javascript:;">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-link faa-shake" aria-hidden="true"></i>
            (ノへ￣、)
          </span>
        </a>
        
      </li>
    
      <li>
        <a href="/">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-leaf faa-wrench" aria-hidden="true"></i>
            关于
          </span>
        </a>
        
          <ul class="sub-menu">
            
              <li>
                <a href="/about/">
                  <i class="fa fa-meetup" aria-hidden="true"></i>
                  我？
                </a>
              </li>
            
              <li>
                <a href="/theme-sakura/">
                  <i class="fa iconfont icon-sakura" aria-hidden="true"></i>
                  主题
                </a>
              </li>
            
          </ul>
        
      </li>
    
      <li>
        <a href="/atom.xml">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-rss faa-pulse" aria-hidden="true"></i>
            RSS
          </span>
        </a>
        
      </li>
    
  </ul>
  <p style="text-align: center; font-size: 13px; color: #b9b9b9;">&copy 2019 hexo-sakura</p>
</div>
<button onclick="topFunction()" class="mobile-cd-top" id="moblieGoTop" title="Go to top" style="display: none;"><i class="fa fa-chevron-up" aria-hidden="true"></i></button>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css">
<script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script>
<!-- require MetingJS -->
<script src="https://cdn.jsdelivr.net/npm/meting@2/dist/Meting.min.js"></script>
<style>
  .aplayer .aplayer-lrc {
    height: 35px;
  }
  .aplayer .aplayer-lrc p{
    font-size: 16px;
    font-weight: 700;
    line-height: 18px !important;
  }
  .aplayer .aplayer-lrc p.aplayer-lrc-current{
    color: #FF1493;
  }
  .aplayer.aplayer-narrow .aplayer-body{
    left: -66px !important;
  }
  .aplayer.aplayer-fixed .aplayer-lrc {
    display: none;
  }
  .aplayer .aplayer-lrc.aplayer-lrc-hide {
      display:none !important;
  }
  .aplayer.aplayer-fixed .lrc-show {
    display: block;
    background: rgba(255, 255, 255, 0.8);
  }
</style>
<meting-js

    id="2660651585"

    server="netease"

    type="playlist"

    fixed="true"

    autoplay="false"

    loop="all"

    order="random"

    preload="auto"

    volume="0.7"

    mutex="true"

</meting-js>
<script>
  $(function(){
    $('body').on('click', '.aplayer', function(){
      if($('.aplayer-button').hasClass('aplayer-play')) {
        $('.aplayer-lrc').removeClass('lrc-show');
      } else {
        $('.aplayer-lrc').addClass('lrc-show');
      }
    })
  });
</script>
</body>
</html>